package com.kira.scaffoldmvc.Controller;

import com.kira.scaffoldmvc.POJO.Book;
import com.kira.scaffoldmvc.POJO.BookIsbn;
import com.kira.scaffoldmvc.POJO.DTO.UpdateDTO;
import com.kira.scaffoldmvc.POJO.Result;
import com.kira.scaffoldmvc.Service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    private BookService bookService;

    @GetMapping("/getTotal")
    public Result getTotal() {
        return bookService.getTotal();

    }

    @GetMapping("/rentBook")
    public Result rentBook(String bookId) {
        return bookService.rentBook(bookId);
    }

    @GetMapping("/backBook")
    public Result backBook(@RequestParam(required = true) String bookId, @RequestParam(required = true) String rentId) {
        return bookService.backBook(bookId, rentId);

    }

    @GetMapping("/getHistory")
    public Result getHistory(String userId, Integer pageNum, Integer pageSize) {

        return bookService.getHistory(userId, pageNum, pageSize);
    }

    @GetMapping("/getAllBook")
    public Result getAllBook(Integer pageNum, Integer pageSize) {

        return bookService.getAllBook(pageNum, pageSize);
    }

    @PostMapping("/InsertBook")
    public Result InsertBook(@RequestBody Book book) {
        return bookService.InsertBook(book);
    }

    @PostMapping("/updateBook")
    public Result updateBook(@RequestBody UpdateDTO dto) {
        return bookService.updateBook(dto);
    }


    @GetMapping("/getBook")
    public Result getBook(@RequestParam String BookId) {
        return bookService.getBook(BookId);
    }

    @GetMapping("/getRent")
    public Result getRent(@RequestParam Integer pageNum, @RequestParam Integer pageSize) {
        return bookService.getRent(pageNum, pageSize);
    }

    @GetMapping("/getByISBN")
    public BookIsbn getByISBN(@RequestParam String isbn) {

        return bookService.getByISBN(isbn);

    }

}
